package handler

import (
	"github.com/gin-gonic/gin"
	request2 "zg3yk/api/request"
	"zg3yk/global"
	"zg3yk/interface/dao"
	"zg3yk/interface/models"
	"zg3yk/pkg"
)

func DanMu(context *gin.Context) {
	var req request2.DanMu
	err := context.ShouldBind(&req)
	if err != nil {
		context.JSON(500, gin.H{
			"code": 500,
			"msg":  err.Error(),
			"data": nil,
		})
		return

	}
	global.DB.Begin()

	bdy := pkg.DanMuByd(req.Danmu)

	if bdy == false {
		context.JSON(500, gin.H{
			"code": 500,
			"msg":  "污秽吃鱼",
			"data": bdy,
		})
		return
	}

	danmu := models.Danmus{
		Id:    req.Id,
		Danmu: req.Danmu,
		Count: uint(req.Count),
	}
	global.DB.Commit()
	dao.Create(&danmu, &danmu)

	context.JSON(200, gin.H{
		"code": 200,
		"msg":  nil,
		"data": danmu,
	})
}
